<template>
  <div id="Detail">
    <v-details
      :detailData="data.detailData"
      :inputConfig="inputConfig"
      :rules="rules"
      @pop="setdata"
      ref="input"
    ></v-details>
  </div>
</template>

<script>
import details from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "AsnDetails",
  mixins: [baseMixin],
  props: {
    data: {
      type: Object,
    },
  },
  data() {
    //自定义验证规则

    return {
      inputConfig: [
        [
          {
            type: "input",
            label: this.$t('outbound.stepnumber'),
            props: "stepnumber",
          },
          {
            type: "select",
            label: this.$t('outbound.fromzone'),
            props: "fromzone",
            options: this.getOptions("queryPutawayzoneDropDown"),
          },
          {
            type: "table",
            label: this.$t('outbound.fromloc'),
            props: "fromloc",
            tableConfig: [
              {
                label: this.$t("config.loc"),
                prop: "loc",
                input: "input",
              },
              {
                label: this.$t("common.type"),
                prop: "locationtype",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCTYPE"),
              },
              {
                label: this.$t("config.area"),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown"),
              },
              {
                label: this.$t("config.locFlag"),
                prop: "locationflag",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG"),
              },
              {
                label: this.$t("config.locCategory"),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCCATEGRY"),
              },
              {
                label: this.$t("config.loseId"),
                prop: "loseid",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t("config.commingleLot"),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t("config.commingleSku"),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t("config.capacity"),
                prop: "cubiccapacity",
                input: "input",
              },
            ],
            url: "/queryLoc/",
          },
          {
            type: "select",
            label: this.$t('outbound.singleputawayformultipallets'),
            props: "singleputawayformultipallets",
            options: this.getOptions("querycodeLkup/YESNO"),
          },
          {
            type: "select",
            label: this.$t('outbound.checkrestrictions'),
            props: "checkrestrictions",
            options: this.getOptions("querycodeLkup/YESNO"),
          },
        ],
        [
          {
            type: "select",
            label: this.$t('outbound.patype'),
            props: "patype",
            options: this.getOptions("querycodeLkup/PATYPE"),
          },
          {
            type: "select",
            label: this.$t('outbound.tozone'),
            props: "zone",
            options: this.getOptions("queryPutawayzoneDropDown"),
          },
          {
            type: "table",
            label: this.$t("config.toLoc"),
            props: "toloc",
            tableConfig: [
              {
                label: this.$t("config.loc"),
                prop: "loc",
                input: "input",
              },
              {
                label: this.$t("common.type"),
                prop: "locationtype",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCTYPE"),
              },
              {
                label: this.$t("config.area"),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown"),
              },
              {
                label: this.$t("config.locFlag"),
                prop: "locationflag",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCFLAG"),
              },
              {
                label: this.$t("config.locCategory"),
                prop: "locationcategory",
                input: "select",
                options: this.getOptions("querycodeLkup/LOCCATEGRY"),
              },
              {
                label: this.$t("config.loseId"),
                prop: "loseid",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t("config.commingleLot"),
                prop: "comminglelot",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t("config.commingleSku"),
                prop: "comminglesku",
                input: "select",
                options: this.getOptions("querycodeLkup/YESNO"),
              },
              {
                label: this.$t("config.capacity"),
                prop: "cubiccapacity",
                input: "input",
              },
            ],
            url: "/queryLoc/",
          },
        ],
        [
          {
            type: "select",
            label: this.$t('outbound.dimensionrestriction01'),
            props: "dimensionrestriction01",
            options: this.getOptions("querycodeLkup/PADIMREST"),
          },
          {
            type: "select",
            label: "",
            props: "dimensionrestriction02",
            options: this.getOptions("querycodeLkup/PADIMREST"),
          },
          {
            type: "select",
            label: "",
            props: "dimensionrestriction03",
            options: this.getOptions("querycodeLkup/PADIMREST"),
          },
          {
            type: "select",
            label: "",
            props: "dimensionrestriction04",
            options: this.getOptions("querycodeLkup/PADIMREST"),
          },
          {
            type: "select",
            label: "",
            props: "dimensionrestriction05",
            options: this.getOptions("querycodeLkup/PADIMREST"),
          },
          {
            type: "select",
            label: "",
            props: "dimensionrestriction06",
            options: this.getOptions("querycodeLkup/PADIMREST"),
          },
        ],
        [
          {
            type: "select",
            label: this.$t('outbound.areatypeexclude01'),
            props: "areatypeexclude01",
            options: this.getOptions("queryAreadetailDropDown"),
          },
          {
            type: "select",
            label: "",
            props: "areatypeexclude02",
            options: this.getOptions("queryAreadetailDropDown"),
          },
          {
            type: "select",
            label: "",
            props: "areatypeexclude03",
            options: this.getOptions("queryAreadetailDropDown"),
          },
          {
            type: "select",
            label: this.$t('outbound.locsearchtype'),
            props: "locsearchtype",
            options: this.getOptions("querycodeLkup/PALOCSORT"),
          },
        ],
      ],
      rules: {
        stepnumber: [{ required: true, trigger: "blur" }],
        patype: [{ required: true, trigger: "blur" }],
        fromloc: [{ validator: this.Validate, trigger: "blur" }],
        toloc: [{ validator: this.Validate, trigger: "blur" }],
      },
    };
  },
  methods: {
    Validate(rule, value, callback) {
      if (value === "") {
        callback();
      } else {
        this.$api.get(`/queryLocByLocKey/${value}`).then((res) => {
          
            if (!res.bean) {
              this.$message.error(this.$t('msg.msg7'));
              this.data.detailData[rule.field] = "";
              callback(new Error());
            } else {
              callback();
            }
        }).catch(e => {
          callback(new Error());
        })
      }
    },
    setdata(data, id, close, listId) {
      if (listId == "0") {
        this.data.detailData.fromloc = data.loc;
      } else if (listId == "1") {
        this.data.detailData.toloc = data.loc;
      }
      close(false);
    },
  },
  mounted() {},
  watch: {},
  components: {
    "v-details": details,
  },
};
</script>

<style scoped></style>
